<?php

namespace App\Console\Commands;

use App\Libraries\Queue\AMQPConsumer;
use App\Libraries\Queue\ReceiptHandleMessage;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use PhpAmqpLib\Message\AMQPMessage;

class WindowReceipt extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'window:receipt';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '消费回执';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        try {
            $queue = config('customs.queue');
            $consumer = AMQPConsumer::instance($queue['host'], $queue['port'], $queue['user'], $queue['password'], $queue['vHost']);
            $consumer->doCallback(new ReceiptHandleMessage);
            $consumer->doProcess($queue['receipt'], $queue['receipt']);

        } catch (Exception $exception) {
            Log::error($exception->getMessage());
        }
    }
}
